from graphics.Shape import Polygon, PolygonGenerator
import tkinter as tk

from PIL import Image, ImageDraw, ImageGrab


def flood_fill(canvas, x, y, new_color):
    img = ImageGrab.grab()  # 获取屏幕图像
    target = img.getpixel((x,y))
    ImageDraw.flood_fill(img, (x,y), new_color, thresh=10)  # 像素级填充[1](@ref)
    # 将处理后的图像显示回Canvas
# 生成五角星顶点
center = (200, 200)
vertices = PolygonGenerator.star(center, points=5, outer_radius=50, inner_radius=20)

# 创建画布并填充
root = tk.Tk()
canvas = tk.Canvas(root, width=400, height=400, bg='white')
canvas.pack()

# 将顶点列表展开为平面坐标序列（Tkinter格式要求）
flat_vertices = [coord for point in vertices for coord in point]

# 绘制填充多边形（黄色填充+蓝色边框）
canvas.create_polygon(
    flat_vertices,
    fill='yellow',        # 填充颜色
    outline='blue',       # 边框颜色
    width=2               # 边框宽度
)

root.mainloop()